﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.member;

namespace Trans.car
{
    public partial class Add_car : Form
    {
        DataRowView row;
        public Add_car()
        {
            InitializeComponent();
        }

        private void Add_car_Load(object sender, EventArgs e)
        {
            row =(DataRowView) tbcarBindingSource.AddNew();
        }

        private void dateTimeInput1_Click(object sender, EventArgs e)
        {

        }


        private void bt_cartype_Click(object sender, EventArgs e)
        {
            Select_cartype f = new Select_cartype();
            
            if((f.ShowDialog()==DialogResult.OK)&&(f.HasSelected))
            {
                lb_cartype.Text = f.Model+"";
                row["cartype_id"] = f.Id;
            }
            else
            {

            }
        }

        private void bt_driver_Click(object sender, EventArgs e)
        {
            Select_driver f = new Select_driver();
            if((f.ShowDialog()==DialogResult.OK)&&(f.HasSelected))
            {
                row["driver_id"] = f.Id;
                lb_driver.Text = f.Name_s;
            }
        }

        private void bt_add_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                try
                {
                    row["state"] = "准备";
                    tbcarBindingSource.EndEdit();
                    tb_carTableAdapter.Update(dataSet.tb_car);
                    this.Close();
                    MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
           
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbcarBindingSource.CancelEdit();
            this.Close();
        }

        private void tx_license_Validating(object sender, CancelEventArgs e)
        {
            if(tx_license.Text.Length>0)
            {
                error.SetError(tx_license, "");
            }
            else
            {
                error.SetError(tx_license, "请输入车牌号");
                e.Cancel = true;
            }
        }

        private void tx_place_Validating(object sender, CancelEventArgs e)
        {
            if (tx_place.Text.Length > 0)
            {
                error.SetError(tx_place, "");
            }
            else
            {
                error.SetError(tx_place, "请输入所在地");
                e.Cancel = true;
            }
        }
    }
}
